set more off

/* This file replicates the results in Table 3, Chegere, Eggert & Söderbom (CES) */ 

/*cd "C:\xxx....*/

discard 
clear all

use "CES2019_data.dta" 

keep if wave==1 & est_sample==1


/* this program uses wild bootstrap procedure for statistical tests */
prog def btf 
boottest {bagstreatment}{traintreatment}{bagstreatment=traintreatment}{sex}{age}{schooling}{activeworkers}{wealth}{maizeexperienceyears}{trained}, cluster (villagecode) reps(999) seed (906453) nogr
end


/* Table 3: Impact on qualitative characteristics (note: infererence is not based on the std errors reported here)  */

foreach yvar in size_shape aroma taste colour infestation rotting qualityindex {
reg `yvar' bagstreatment traintreatment sex age schooling activeworkers wealth maizeexperienceyears trained, cluster(villagecode)
btf
}

/* Obtain p-values by means of randomised inference ("randomization-t randomized p-value") for treatment effects */

foreach yvar in size_shape aroma taste colour infestation rotting qualityindex {
randcmd ((bagstreatment traintreatment) reg `yvar' bagstreatment traintreatment sex age schooling activeworkers wealth maizeexperienceyears trained, cluster(villagecode)), treatvars(bagstreatment traintreatment)  groupvar(village)
}


/* Note: the variable qualityindex (which already exists in the dataset) was computed like this: */
/*
pca size_shape aroma taste colour infestation rotting
predict qualityindex2
*/

exit

